<template>
    <div>
        <h1>列表</h1>
        <div>
            姓名:<input type="text" v-model="info.userName">
            <select v-model="info.levelId">
                <option value="">请选择</option>
                <option :value="item.memberLevelId" v-for="item in levelList" :key="item.memberLevelId">
                    {{ item.memberLeveName }}</option>
            </select>
            <input type="button" value="查询" @click="GetVipList">
        </div>
        <table class="table table-database">
            <tbody>
                <tr>
                    <td>Id</td>

                    <td>手机号</td>
                    <td>会员名称</td>
                    <td>会员等级</td>
                    <td>生日</td>
                    <td>性别</td>
                    <td>积分</td>
                    <td>余钱</td>
                    <td>爱好</td>
                    <td>简介</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>

                <tr v-for="item in vipList" :key="item.id">
                    <td>{{ item.id }}</td>

                    <td>{{ item.tel.substring(0, 3) + '****' + item.tel.substring(7) }}</td>
                    <td>{{ item.userName }}</td>
                    <td>{{ item.memberLeveName }}</td>
                    <td>{{ moment(item.birthday).format('yyyy-MM-DD') }}</td>
                    <td>{{ item.gender == 1 ? '男' : '女' }}</td>
                    <td>{{ item.score }}</td>
                    <td>￥{{ item.money }}</td>
                    <td>{{ item.likes }}</td>
                    <td>{{ item.desc }}</td>
                    <td>
                        {{ item.state }}
                        <input type="button" value="解冻" v-if="item.state == 1">
                        <input type="button" value="冻结" v-if="item.state == 0">
                    </td>
                    <td>
                        <input type="button" value="删除">

                        <input type="button" value="解冻" v-if="item.state == 0" @click="updata(item.id, 1)">
                        <input type="button" value="冻结" v-if="item.state == 1" @click="updata(item.id, 0)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref, reactive, onMounted } from 'vue';

let info: any = reactive({
    userName: '',
    vipId: '',
});

let vipList: any = ref([]);
let levelList: any = ref([]);

onMounted(() => {
    GetVipList();
    getViplevelList();
});
const getViplevelList = () => {
    axios({
        url: 'https://localhost:7278/api/User/Modber',
        method: 'get',
    })
        .then((res) => {
            console.log(res);
            levelList.value = res.data;
        })
        .catch((err) => {
            console.log(err);
        });
};
const GetVipList = () => {
    axios({
        url: 'https://localhost:7278/api/User/GetMember',
        method: 'get',
        params: info,
    })
        .then((res) => {
            console.log(res);
            vipList.value = res.data;
        })
        .catch((err) => {
            console.log(err);
        });
};




const updata = (id: any, state: any) => {
    console.log(id, state);

    let f = confirm('确定修改吗');
    if (f) {
        axios({
            url: 'https://localhost:7278/api/User/Updata',
            method: 'put',
            params: {
                id: id,
                state: state,
            },
        })
            .then((res) => {
                console.log(res);
                if (res.data > 0) {
                    alert('修改成功');
                    GetVipList();
                } else {
                    alert('修改成功');
                    return;
                }
            })
            .catch((err) => {
                console.log(err);
            });
    }
};



</script>

<style scoped></style>